package cn.jbt.api.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.jbt.api.admin.annotation.Log;
import cn.jbt.api.admin.entity.CmsPlaceInfo;
import cn.jbt.api.admin.service.ICmsPlaceInfoService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cms/placeInfo")
@Slf4j
@AllArgsConstructor
public class CmsPlaceInfoController {

    private final ICmsPlaceInfoService iCmsPlaceInfoService;

    @PostMapping("/list")
    @SaCheckPermission("cms:placeInfo:list")
    @Log(bizType = "查询", bizName = "查询推荐位列表")
    public List<CmsPlaceInfo> getAll(@RequestBody CmsPlaceInfo cmsPlaceInfo) {
        return iCmsPlaceInfoService.getAll(cmsPlaceInfo);
    }

    @PostMapping("/add")
    @SaCheckPermission("cms:placeInfo:add")
    @Log(bizType = "新增", bizName = "新增推荐位")
    public CmsPlaceInfo add(@Valid @RequestBody CmsPlaceInfo cmsPlaceInfo) {
        return iCmsPlaceInfoService.add(cmsPlaceInfo);
    }

    @PostMapping("/edit")
    @SaCheckPermission("cms:placeInfo:edit")
    @Log(bizType = "编辑", bizName = "编辑推荐位")
    public CmsPlaceInfo edit(@Valid @RequestBody CmsPlaceInfo cmsPlaceInfo) {
        return iCmsPlaceInfoService.edit(cmsPlaceInfo);
    }

    @PostMapping("/del")
    @SaCheckPermission("cms:placeInfo:del")
    @Log(bizType = "删除", bizName = "删除推荐位")
    public void del(@NotEmpty @RequestBody List<Long> ids) {
        iCmsPlaceInfoService.del(ids);
    }

}
